package src.com.atguigu04.set.interview;

import java.util.HashSet;

/**
 * @author shkstart
 * @create 15:35
 */
public class HashSetDemo {
    public static void main(String[] args) {
        HashSet set = new HashSet();
        Person p1 = new Person(1001,"AA");
        Person p2 = new Person(1002,"BB");

        set.add(p1);
        set.add(p2);
        System.out.println(set);//两个

        p1.name = "CC";//只是把“AA”改为“CC”，哈希值不变
        set.remove(p1);//remove(p1) ==> remove(new Person(1001,"CC"))的哈希值 而非“AA”的哈希值
        System.out.println(set);//二个

        set.add(new Person(1001,"CC"));//加的是“CC”的哈希值
        System.out.println(set);

        set.add(new Person(1001,"AA"));//这用equals()方法了
        System.out.println(set);

    }
}
